<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/1/15
 * Time: 23:05
 */
namespace app\api\logic;



use app\common\model\zbtask\Zbcategory;

class Category
{

    private static $new;
    private $cate;
    private function __construct() {
        $this->cate = new Zbcategory();
    }


    public static function instance () { //声明一个静态公共方法，供外部获取唯一实例
        if (!(self::$new instanceof self)) {
            self::$new = new self;
        }
        return self::$new;
    }

    /**
     * 获取所有分类
     */
    public function getAll($limit = 8) {
        $query = $this->cate->order('sort asc');
        if ($limit) {
            $query->limit($limit);
        }
        $all = $query->select();

        return $all;
    }

    private function __clone() {} //声明私有的克隆方法，防止对象被克隆

    public function __sleep() { //重写__sleep方法，将返回置空，防止序列化反序列化获得新的对象
        return [];
    }

}